
#ifndef _MEMBER_BSOCKET_H_
#define _MEMBER_BSOCKET_H_

#include <BString>
#include <BSocket>

#define socket_member(socket)			((member_BSocket*)((BSocket*)socket)->_ptr)

#ifdef linux
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#endif

#ifdef _WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <Windows.h>
#undef min
#undef max
#endif

namespace BWE
{
	class member_BSocket
	{
	public:
		member_BSocket(BSocket* socket);
		~member_BSocket();
		
		bool create(int domain, int type, int protocol);
		bool setnonblock();

		bool select(double seconds) const;
		void checkError();

		BSocket*		boss;
		BString			address;
		int				port;
		BByteArray		buffer;
		int				error;
		const char*		errorStr;
		BSocket::State	state;
		sockaddr_in		addr;
		
#ifdef linux
		int				sock;
#endif

#ifdef _WIN32
		SOCKET			sock;
#endif
		
	};
}


#endif
